package com.example.Laboratory.Service.Impl;

import com.example.Laboratory.Entity.Researcher;
import com.example.Laboratory.Mapper.ResearcherMapper;
import com.example.Laboratory.Service.ResearcherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ResearcherServiceImpl implements ResearcherService {

    @Autowired
    ResearcherMapper researcherMapper;

    //增加研究队伍-人员名单信息
    @Override
    public String addResearcher(Researcher r) {
        if (researcherMapper.addResearcher(r) == 1) {
            return "添加成功";
        } else {
            return "添加失败";
        }
    }

    //根据id删除信息
    @Override
    public String deleteResearcher(int researcher_id) {
        if (researcherMapper.deleteResearcher(researcher_id) == 1) {
            return "删除成功";
        } else {
            return "删除失败";
        }
    }

    //查找全表信息根据教授，副教授，高级工程师，讲师排序
    @Override
    public List<Researcher> researchResearcher() {
        List<Researcher> Researcher1 = researcherMapper.researchResearcher1();
        List<Researcher> Researcher2 = researcherMapper.researchResearcher2();
        List<Researcher> Researcher3 = researcherMapper.researchResearcher3();
        List<Researcher> Researcher4 = researcherMapper.researchResearcher4();
        List<Researcher> Researcher = new ArrayList<Researcher>();

        Researcher.addAll(Researcher1);
        Researcher.addAll(Researcher2);
        Researcher.addAll(Researcher3);
        Researcher.addAll(Researcher4);

        return Researcher;
    }

    //用全部信息修改
    @Override
    public String reviseResearcher(Researcher r) {
        if (researcherMapper.reviseResearcher(r) == 1) {
            return "修改成功";
        } else {
            return "修改失败";
        }
    }
}
